page.pageInit = function(){
  //初始化tree
  TreeCtr.treeInit("#sysResourcesTree");
  //初始化grid
  GirdCtr.gridInit();
  GirdCtr.buttonBind()
}

var TreeCtr = $.extend({},defaultZtreeConFig,{
	setting:{
		view: {
			selectedMulti: false
		},
		async: {
			enable: true,
			url:contextPath+"/tcc/app/appTree.htm",
			autoParam:["id", "name=n", "level=lv"],
			otherParam:{"otherParam":"zTreeAsyncTest"},
		    dataType:"json"
		},
		callback: {
			onClick: function(e,id,node){
			   //主GIRD刷新
			   GirdCtr.gridQuery({applicationName:node.value.appCode})
			   GirdCtr.applicationName = node.value.appCode;
			}
		}
	}
});

//grid控制器
var GirdCtr =  $.extend({},defaultGridConFig,{
   gridInit: function(){
	 var _this = this;
	//创建jqGrid组件
	_this.grid = $("#menuGrid").jqGrid({
		 			datatype: "json",
		 			url : contextPath+'/tcc/compensate/query.htm',//组件创建完成之后请求数据的url
					datatype : "json",//请求数据返回的类型。可选json,xml,txt
					colModel : [ //jqGrid每一列的配置信息。包括名字，索引，宽度,对齐方式.....
					             {label:"事物ID", name : "transId",sortable:false,key:true,align : "center"},
					             {label:"重试次数", name : 'retriedCount',sortable:false,width :60,align : "center"}, 
					             {label:"版本", name : 'version',sortable:false,width : 70,align : "center"}, 
					             {label:"事物接口", name : 'targetClass',sortable:false,width : 280,align : "center"}, 
					             {label:"执行方法", name : 'targetMethod',sortable:false,width : 160,align : "center"}, 
					             {label:"确认方法", name : 'confirmMethod',sortable:false,width : 160,align : "center"},
					             {label:"取消方法", name : 'cancelMethod',sortable:false,width : 160,align : "center"}
					           ],
		            shrinkToFit:false,   
		            autoScroll: true, 
					rowNum : 10,//一页显示多少条
					rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
					rownumWidth: 20, //设置显示序号的宽度，默认为25  
					pager : '#menuGridPager',//表格页脚的占位符(一般是div)的id
					sortname : 'sort',//初始化的时候排序的字段
					sortorder : "asc",//排序方式,可选desc,asc
					mtype : "post",//向后台请求数据的ajax的类型。可选post,get
					width:page.window.grid.width-200,
					height:page.window.grid.height
				});
		/*创建jqGrid的操作按钮容器*/
		/*可以控制界面上增删改查的按钮是否显示*/
		$("#menuGrid").jqGrid('navGrid', '#menuGridPager', {edit:false,del:false,add:false,search:false,refresh:false});
	},
	buttonBind:function(){//控制按钮初始化
	  var _this = this;
	  $("#editBtn").bind("click",function(){_this.event.doEdit(_this,this)});
	  $("#deleteBtn").bind("click",function(){_this.event.doDelete(_this,this)});
	},
	event:{//事件
	  doEdit:function(_this,btn){//修改
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = node;
			  params.menuId = menuId;
			  params.applicationName= GirdCtr.applicationName;
			  showWindow("修改流程",contextPath+"/tcc/compensate/editView.htm",params,function(){
				  GirdCtr.reLoad();
			  });
		  }else{
			  layer.msg("选择需要修改的数据");
		  }
	  },
	  doDelete:function(_this,btn){//删除
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			 var laIndex = layer.confirm('确定要删除该数据吗？', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					_this.event.gridDoDelete(node,_this);
					layer.close(laIndex);
				});
		  }else{
			  layer.msg("请选择删除的数据.");
		  }
	  },gridDoDelete:function(node,_this){
		  $.dataPost(contextPath+'/tcc/compensate/delete.htm',{id:node.transId,applicationName: GirdCtr.applicationName},function(result){
			  if(result.success){
				  GirdCtr.reLoad();
			  }else{
				  layer.msg(result.msg); 
			  }
		  });
	  }
	}
});


